
document.write("<iframe id='popupFrame' name='popupFrame' style='border: 0px outset; display:none;background-color:#dcdcdc; position:absolute;width:390px;height:150px;z-index=105' frameborder=0 MARGINHEIGHT='0' MARGINWIDTH='0' SCROLLING='auto'></iframe>");


function Popup(o,choice, name) 
{	
    $('#popupFrame').focus();
    try{
        buildPick(o,name);
        //alert("o.parentElement.firstChild="+o.parentElement.firstChild);
        return;
    }
    catch(e){
        alert(e.description);
    }
}
            
function buildPick() 
{
    PopupField = arguments[0];
    PopUpFrame = document.getElementById("popupFrame");
    PopUpFrame.style.left = getAbsX(PopupField) + "px";
    PopUpFrame.style.top= getAbsY(PopupField) + 20 + "px";
    var ftype = 0;
    if( typeof(PopupField.fieldtype) != 'undefined')
        ftype = PopupField.fieldtype;
  
    ftype = parseInt(ftype);

    var sHTML="";
    switch(ftype)
    {
        case 0: //General 
            sHTML = drawPickSelect(ftype, arguments[1]);
            PopUpFrame.style.width  = "400px";
            PopUpFrame.style.height = "280px";
            break;
        default:
    }
 	
    if(ftype != 2) {
        var PopUpobj = document.getElementById("popupFrame");
        self.popupFrame.document.open();
        self.popupFrame.document.write(sHTML);
        self.popupFrame.document.close();
        //PopUpFrame.style.display = "block";
        $(PopUpobj).fadeIn(500);
    } 
  
    if(ftype == 4) {
        PopUpFrame.style.display = "none";
    }
  
}

function drawPickSelect(picktype, name)
{	
    // Generate HTML
    sHTML = '<html><head>';
    sHTML += '<link href="assets/css/bootstrap.css" rel="stylesheet">';
    sHTML += '<script>';  
    sHTML += '</script>';
  
    sHTML += '<style type="text/css">';
    sHTML += 'body { width: 100%;overflow:hidden;font-family:Arial, Helvetica, sans-serif; font-size:12px;}';
    sHTML += '.header {width: 100%;margin:2px; padding: 2px; overflow:hidden; font-size:13px; font-weight: bold}';
    sHTML += '.subheading {font-size:11px; font-weight:bold; color: #62686A}';
    sHTML +=  '.textarea-wrapper { border: 1px solid #CDEBF4;}';
    sHTML += '.contents {background-color: white; height:70%; width:100%;margin:15px 0px 0px 0px; padding: 5px; overflow-y:auto;}</style>';
    sHTML += '</head><body>';
  
    sHTML += '<div class="alert alert-success">';
    sHTML += '<button type="button" class="close" onclick="parent.HidePick();">&times</button>';
    sHTML += '<strong>' + name + '</strong>';
          
    sHTML += '<div class="contents alert alert-block well">'; 
    sHTML += '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas posuere pretium lectus sed pellentesque. Sed feugiat, magna at ultrices pretium, tortor arcu vulputate leo, at posuere elit augue nec sem. Etiam hendrerit nulla sagittis neque mollis sit amet porta eros iaculis. </p>';
    sHTML += '</div>';
    sHTML += '</div>';
    sHTML +=  '</body></html>';
		
    return sHTML;
 
}
  
function HidePick()
{
    var PopUpobj = document.getElementById("popupFrame");
    try{
        $(PopUpobj).fadeOut(500);
        //PopUpFrame.style.display = "none";   
    } catch(e){  }
}

function onbodyclick()
{
    try
    {
        //alert(event.srcElement.tagName);
        if(event.srcElement.tagName != "I")
        {
            HidePick();
        }
    }
    catch(e){}
}

function getAbsX(elt) {
    return (elt.x) ? elt.x : getAbsPos(elt,"Left");
}
function getAbsY(elt) {
    return (elt.y) ? elt.y : getAbsPos(elt,"Top");
}
function getAbsPos(elt,which) 
{
    iPos = 0;
    while (elt != null) 
    {
        iPos += elt["offset" + which];
        elt = elt.offsetParent;
    }
    return iPos;
}

